package com.hzx.controller;

import com.hzx.dao.CommodityMapper;
import com.hzx.pojo.Commodity;
import com.hzx.pojo.User;
import com.hzx.service.CommodityService;
import com.hzx.service.UserInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServer;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

@Controller
public class SingleProductController {


    @Autowired
     private CommodityService commodityService;

    @Autowired
    private UserInformationService userInformationService;


    @GetMapping("/single-product.html")
    public String singleproduct(HttpServletRequest request,Model model, @RequestParam Integer id){  // 传入 商品 的 id
        Integer uid = (Integer) request.getSession().getAttribute("uid") ;

        Commodity commodity = commodityService.selectByid(id); // 通过 id 获得 商品信息
        User user = userInformationService.getUserByUid(uid);
        model.addAttribute("commodity",commodity);
        model.addAttribute("user",user);

        return "single-product" ;
    }
}
